#pragma once

#include <boostext/util/make_shared.hpp>
#include <QtCore/QAbstractItemModel>

#include "Project.hpp"
#include "Script.hpp"
#include "UiDefinition.hpp"




namespace Engine
{
	namespace Edit
	{
		class ProjectModel
			: public QAbstractItemModel
		{
			Q_OBJECT

		public:

			SHARED(ProjectModel);
			ProjectModel(Project::ptr project);
			virtual ~ProjectModel();



			QModelIndex indexFromItem(ProjectItem::ptr item) const;
			ProjectItem::ptr itemFromIndex(const QModelIndex& index) const;
			virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
			virtual QModelIndex parent(const QModelIndex& index) const;
			virtual int rowCount(const QModelIndex& parent) const;
			virtual int columnCount(const QModelIndex& parent) const;
			virtual Qt::ItemFlags flags(const QModelIndex& index) const;
			virtual QVariant data(const QModelIndex& index, int role = Qt::EditRole) const;
			virtual bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole);

		signals:

			/**
			 * This signal is emitted whenever the project is modified
			 * through the setData method.
			 */
			void modified();

		protected:

			ProjectItem::Result projectModified(ProjectItem::weak_ptr item, ProjectItem::Action action);

			void beginAddChild(ProjectItem::weak_ptr item);
			void endAddChild(ProjectItem::weak_ptr item);

			void beginRemoveChild(ProjectItem::weak_ptr item);
			void endRemoveChild(ProjectItem::weak_ptr item);

		private:

			typedef boost::unordered_map<ProjectItem::Type, QPixmap>   ItemMap;

			Project::ptr   m_project;
			ItemMap        m_icons;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
